<?php

class PortalWebServiceDataMembership extends PortalWebServiceDataBase{
/*
	//plan status
	const PLAN_STATUS_WAITING       = 0;
	const PLAN_STATUS_NORMAL        = 1;
	const PLAN_STATUS_PROCESSING    = 2;
	const PLAN_STATUS_SUSPEND       = 3;
	const PLAN_STATUS_PAY_REJECTED  = 4;
	const PLAN_STATUS_CANCELED      = 5;
	const PLAN_STATUS_COMPLEATED    = 6;
	
	public static $plan_status = array(
		self::PLAN_STATUS_WAITING       => 'Next order plan awaiting to process',
		self::PLAN_STATUS_NORMAL        => 'Transaction accepted from bank',
		self::PLAN_STATUS_PROCESSING    => 'Package created and awaiting transaction status from bank',
		self::PLAN_STATUS_SUSPEND       => 'Member suspend by tvb administrator',
		self::PLAN_STATUS_PAY_REJECTED  => 'Transaction rejected from bank',
		self::PLAN_STATUS_COMPLEATED    => 'Package end',
		self::PLAN_STATUS_CANCELED      => 'Package record cancelled by system'
	);
	
	//status
	const STATUS_MEMBER_NEW_REG         = 0;
	const STATUS_MEMBER_REG_CONFIRMED   = 1;
	const STATUS_MEMBER_ACTIVE          = 2;
	const STATUS_MEMBER_TEMP_SUP        = 3;
	const STATUS_MEMBER_REG_EXPIRED     = 4;
	const STATUS_MEMBER_INACTIVE        = 5;
	const STATUS_MEMBER_EMAIL_CHANGED   = 6;
	const STATUS_MEMBER_EMAIL_UPDATE    = 7;
	const STATUS_MEMBER_EMAIL_CONFIRMED = 8;
	
	public static $member_status = array(
		self::STATUS_MEMBER_NEW_REG         => "New Registration",
		self::STATUS_MEMBER_REG_CONFIRMED   => "Registration Confirmed",
		self::STATUS_MEMBER_ACTIVE          => "Active",
		self::STATUS_MEMBER_TEMP_SUP        => "Temporarily Suspended",
		self::STATUS_MEMBER_REG_EXPIRED     => "Registration Expired",
		self::STATUS_MEMBER_INACTIVE        => "Inactive",
		self::STATUS_MEMBER_EMAIL_CHANGED   => "Email Changed",
		self::STATUS_MEMBER_EMAIL_UPDATE    => "Email Updated",
		self::STATUS_MEMBER_EMAIL_CONFIRMED => "Email Confirmed"
	);
	
	//payment status
	const STATUS_PAYMENT_NO        = 0;
	const STATUS_PAYMENT_YES       = 1;
	const STATUS_PAYMENT_EXISTED   = 1101;
	const STATUS_PAYMENT_BLACK     = 1102;
	const STATUS_PAYMENT_INVALID   = 1103;
	const STATUS_PAYMENT_NOT_EXIST = 1104;
	const STATUS_PAYMENT_NULL      = 1105;
	
	public static $payment_status = array(
		self::STATUS_PAYMENT_NO         => "No",
		self::STATUS_PAYMENT_YES        => "Yes",
		self::STATUS_PAYMENT_EXISTED    => "Login id already existed",
		self::STATUS_PAYMENT_BLACK      => "Login id is black",
		self::STATUS_PAYMENT_INVALID    => "Login id is not valid format",
		self::STATUS_PAYMENT_NOT_EXIST  => "Login id is not existed",
		self::STATUS_PAYMENT_NULL       => "Login id is null"
	);
*/
	
	/*
		case 'membership.status':
		case 'membership.profile':
		case 'membership.viewhistory ':
	 */
	// {{{ public function _status($id,$format='json')
	public function _status($id,$format='json')
	{
		$format = $this->__check_format($format);

		$params = array('login_id' => $id);
		$client = new MSApiClient();
/*
		$mspay_plandata = $client->restRequest("MSPay", "getUserCurrentPlan", $params);
		$mspay_userdata = $client->restRequest("MSPay", "getUserAndPaymentStatus", $params);
		//$data['status'] = $mspay_userdata->data->user_status;
		//$data['statusDesc'] = self::$member_status[$data['status']];
		$data['status'] = $mspay_plandata->status;
		$data['statusDesc'] = self::$plan_status[$data['status']];
		$data['errCode'] = $mspay_userdata->errCode;
		$data['errMsg'] = $mspay_userdata->info;
*/
		$data = $client->restRequest("Member", "getPayUserStatus", $params);
		return ($format=='xml' ? CommonUtils::arrayToXml($data) : $data);
	}
	// }}}
	
	// {{{ public function _profile($id,$format='json')
	public function _profile($id,$format='json')
	{
		$format = $this->__check_format($format);

		//$data = array('result'=>'', 'retFlag'=>0);
		//if (empty($id)) {
		//	$data['retFlag'] = 1105;
		//	return $data;
		//}
		$params = array('login_id' => $id);
		$client = new MSApiClient();
/*
		$chkid = $client->restRequest("Member", "checkLoginId", $params);
		if ($chkid == 'block') {
			$data['retFlag'] = 1102;
			return $data;
		}
		if ($chkid == 'illegal') {
			$data['retFlag'] = 1103;
			return $data;
		}
*/
		$data = $client->restRequest("Member", "getUserInfoByLoginId", $params);
		//if (($data->result->status == '0') || ($data->result->status == '5')) {
		//	//$data->retFlag = 1106;
		//	$data = array('result'=>'', 'retFlag'=>1106);
		//}
		return ($format=='xml' ? CommonUtils::arrayToXml($data) : $data);
	}
	// }}}
	
	// {{{ public function _viewhistory($id,$format='json')
	public function _viewhistory($id,$format='json')
	{
		$format = $this->__check_format($format);

	}
	// }}}
	
	// {{{ public function _paymentstatus($id,$format='json')
	public function _paymentstatus($id,$format='json')
	{
		$format = $this->__check_format($format);

		//if(empty($id)) return null;
		$params = array('login_id' => $id);
		$client = new MSApiClient();
		//$chkid = $client->restRequest("Member", "checkLoginId", $params);
		//if ($chkid == 'block' || $chkid == 'illegal') {
		//	return null;
		//}
/*
		$mspay_data = $client->restRequest("Member", "getPayUserStatus", $params);
		$data['result'] = (int) $mspay_data->status;
		//$data['resultDesc'] = self::$payment_status[$data['result']];
		$data['resultDesc'] = $mspay_data->statusDesc;
*/
		$data = $client->restRequest("Member", "isPayUser", $params);
		return ($format=='xml' ? CommonUtils::arrayToXml($data) : $data);
	}
	// }}}
}
